Ext.define('DCApp.controller.DetailController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.detail',

    requires: [
        'Ext.window.Toast'
    ],
    onBackClick: function() {
     	var vm = this.getViewModel();
     	var nd = vm.type.replace('detail','list');
    	 this.redirectTo(nd);
    },    
    onSaveClick: function() {
    	var title = this.getView().title;
        var form = this.lookupReference('form'),rec;        
        if (form.isValid()) {
            rec = this.getViewModel().get('theObj');
            Ext.Msg.wait('保存', '保存'+title+'中...');
            rec.save({
                scope: this,
                callback: this.onComplete
            });
        }
    },

    onComplete: function() {
    	var title = this.getView().title;
        Ext.Msg.hide();
        Ext.toast({
            title: '保存',
            html: title+'保存完成',
            align: 't',
            bodyPadding: 10
        });
        this.onBackClick();
    },
    //获得仿真数据总数
    getEntityCount:function(){
    	var vm = this.getViewModel();
    	var cn  = Ext.getClassName(vm.data.theObj);
    	var pos=cn.lastIndexOf('.');
    	return DCApp.Cfg.SIM_ENM[cn.substring(pos+1)];
    },
    onNext: function() {
    	var token = Ext.util.History.getToken();
    	var pos = token.lastIndexOf('/');
    	var sid= parseInt(token.substring(pos+1));
    	sid++;
    	if(sid>this.getEntityCount())
    		sid=1;
    	this.redirectTo(token.substring(0,pos+1)+sid);
    },
    onPrev: function() {
    	var token = Ext.util.History.getToken();
    	var pos = token.lastIndexOf('/');
    	var sid= parseInt(token.substring(pos+1));
    	sid--;
    	if(sid<1)
    		sid=this.getEntityCount();
    	this.redirectTo(token.substring(0,pos+1)+sid);
    }
    
});
